//
//  NSMutableArray+WXUtility.m
//  CommonFramework
//
//  Created by leev on 2017/10/24.
//  Copyright © 2017年 XES. All rights reserved.
//

#import "NSMutableArray+WXUtility.h"

@implementation NSMutableArray (WXUtility)

/**
 * @desc 判断该数组是否为空
 */
- (BOOL)isSafe
{
    BOOL isSafe = self.count > 0 ? YES : NO;
    return isSafe;
}


/**
 * @desc 将数组中的某一元素移至指定的下标位置
 *
 * @param object 要移动的对象
 *
 * @param index 要移至的下标
 */
- (void)bringObject:(id)object toIndex:(NSInteger)index
{
    if ([self containsObject:object] == NO) {
        return;
    }else{
        //object在移动之前的下标
        NSInteger objIndex = [self indexOfObject:object];
        if (objIndex == index) {
            //如果位置没变,则直接返回
            return;
        }else{
            //先将该对象再次加入到数组中
            [self insertObject:object atIndex:index];
            //然后将之前的对象从数组中删除
            if (objIndex > index) {
                [self removeObjectAtIndex:objIndex + 1];
            }else{
                [self removeObjectAtIndex:objIndex];
            }
        }
    }
}

@end
